/*
 * Copyright (c) 2011 by Konstantin Pavlov.
 */

package gwtlx.html5.client.forms;

import com.google.gwt.dom.client.Element;

/**
 * This class extends standard GWT {@link com.google.gwt.user.client.ui.TextBox}
 * by providing <code>placeholder</code>, and <code>required</code> attributes of the DOM element.
 * <p/>
 * Rendered like this: <code>&lt;input type="text" placeholder="Your name" required="required"/&gt;</code>.
 *
 * @author Konstantin Pavlov
 * @version $LastChangedRevision: 19 $
 * @since 09.01.11
 */
public class TextBox extends com.google.gwt.user.client.ui.TextBox {

    public TextBox() {
        super();
    }

    protected TextBox(Element element) {
        super(element);
    }

    /**
     * Set a placeholder text (a "grayed" text displayed when field is empty
     * and has no focus.
     * <p/>
     * When browser has native support for <code>placeholder</code> attribute - uses this browser feature.
     * Otherwise, focus and blur handlers are added to support this behaviour.
     *
     * @param text A placeholder text.
     */
    public void setPlaceholder(String text) {
        Html5Helper.setPlaceholder(this, text);
    }

    public String getPlaceholder() {
        return Html5Helper.getPlaceholder(this);
    }

    public void setRequired(boolean required) {
        Html5Helper.setRequired(this, required);
    }

    public boolean isRequired() {
        return Html5Helper.isRequired(this);
    }

    public void setAutofocus(boolean autofocus) {
        Html5Helper.setAutofocus(this, autofocus);
    }

    /**
     * Returns value of <code>autofocus</code> property.
     *
     * @return true if aftofocus enabled for this field
     */
    public boolean isAutofocus() {
        return Html5Helper.isAutofocus(this);
    }
}
